import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import java.util.Enumeration;

public class ServletContextAttributeListenerDemo implements ServletContextAttributeListener {
    @Override
    public void attributeAdded(ServletContextAttributeEvent scae) {
        System.out.println("加入属性");

        //1.获取事件源对象
        ServletContext servletContext = scae.getServletContext();
        //2.获取所有名称枚举
        Enumeration<String> names = servletContext.getAttributeNames();
        //3.遍历
        while (names.hasMoreElements()){
            String key = names.nextElement();
            Object value = servletContext.getAttribute(key);
            System.out.println(key+"---"+value);
        }
    }

    @Override
    public void attributeRemoved(ServletContextAttributeEvent scae) {
        System.out.println("移除了属性---");
    }

    @Override
    public void attributeReplaced(ServletContextAttributeEvent scae) {
        System.out.println("属性替换----");
    }
}
